<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/23
 * Time: 00:51
 */

namespace app\wechat\service;
use app\common\library\Service;
use EasyWeChat\Factory;

/**
 * Class OfficialAccount
 * @package app\wechat\service
 */
class OfficialAccount extends Service
{
    protected $appliction = null;

    protected $instance  = null;

    public function _initialize()
    {
        parent::_initialize();
        $config = config('wechat');
        $this->appliction = Factory::officialAccount($config);
        $this->instance = $this->appliction;
    }

    public function __get($name)
    {
        $this->instance = $this->appliction->$name;
        return $this->instance;
    }

    public function __call($name, $arguments)
    {
        $result = $this->instance->$name($arguments);
        if($result['errcode'] !== 0) {
            $this->error = $result['errmsg'];
            return false;
        } else {
            return true;
        }
    }
}